home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_9.zip
/
PREDEF1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-27
|
43KB
|
1,821 lines
/*
* Copyright (C) 1985-1992 New York University
*
* This file is part of the Ada/Ed-C system. See the Ada/Ed README file for
* warranty (none) and distribution info and also the GNU General Public
* License for more details.
*/
/* +---------------------------------------------------+
| |
| I N T E R P P R E D E F S |
| (C Version) |
| |
| Adapted From Low Level SETL version written by |
| |
| Monte Zweben |
| Philippe Kruchten |
| Jean-Pierre Rosen |
| |
| Original High Level SETL version written by |
| |
| Clint Goss |
| Tracey M. Siesser |
| Bernard D. Banner |
| Stephen C. Bryant |
| Gerry Fisher |
| |
| C version written by |
| |
| Robert B. K. Dewar |
| |
+---------------------------------------------------+ */
/* This module contains routines for the implementation of some of
* the predefined Ada packages and routines, namely SEQUENTIAL_IO,
* DIRECT_IO, TEXT_IO, and CALENDAR. Part 1 contains the PREDEF
* routine which executes a predefined operation.
*/
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>
#include "ipredef.h"
#include "intbp.h"
#include "intcp.h"
#include "predefp.h"
/*
* Environment variable to save stack pointer for PREDEF_RAISE. On entry to
* PREDEF, raise_env saves the stack environment (using set_jmp). If an Ada
* exception is signalled, then the PREDEF_RAISE routine raises the exception
* using the usual raise procedure, and then exits directly at the top level
* of the PREDEF procedure, using longjmp.
*/
jmp_buf raise_env;
static int string_offset(int *);
/* Procedure called by main interpreter to execute predefined operation. The
* operation code has been read from the code stream and is passed as the
* parameter. The remaining parameters are stacked as needed.
*/
void predef() /*;predef*/
{
/* This procedure handles all predefined operations. It is passed a marker
* which determines the operation to be performed. The formal parameters of
* the original call have been evaluted onto CURSTACK, but must not be
* popped as then will be discarded by the code. In the case of generic
* procedures, the type template address is pushed on the parameters AND
* MUST BE POPPED!
*/
/* First capture environment for use by PREDEF_RAISE */
if (setjmp(raise_env))
return;
/* Switch on the operation code */
switch(operation) {
/* 14.2.1 FILE MANAGEMENT */
/* SEQUENTIAL_IO: */
/* procedure CREATE(FILE : in out FILE_TYPE; */
/* MODE : in FILE_MODE := OUT_FILE; */
/* NAME : in STRING := ""; */
/* FORM : in STRING := ""); */
case P_SIO_CREATE:
{
open_seq_io('C');
break;
}
/* DIRECT_IO: */
/* procedure CREATE(FILE : in out FILE_TYPE; */
/* MODE : in FILE_MODE := INOUT_FILE; */
/* NAME : in STRING := ""; */
/* FORM : in STRING := ""); */
case P_DIO_CREATE:
{
open_dir_io('C');
break;
}
/* TEXT_IO: */
/* procedure CREATE(FILE : in out FILE_TYPE; */
/* MODE : in FILE_MODE := OUT_FILE; */
/* NAME : in STRING := ""; */
/* FORM : in STRING := ""); */
case P_TIO_CREATE:
{
open_textio('C');
break;
}
/* SEQUENTIAL_IO: */
/* procedure OPEN(FILE : in out FILE_TYPE; */
/* MODE : in FILE_MODE; */
/* NAME : in STRING; */
/* FORM : in STRING := ""); */
case P_SIO_OPEN:
{
open_seq_io('O');
break;
}
/* DIRECT_IO: */
/* procedure OPEN(FILE : in out FILE_TYPE; */
/* MODE : in FILE_MODE; */
/* NAME : in STRING; */
/* FORM : in STRING := ""); */
case P_DIO_OPEN:
{
open_dir_io('O');
break;
}
/* TEXT_IO: */
/* procedure OPEN(FILE : in out FILE_TYPE; */
/* MODE : in FILE_MODE; */
/* NAME : in STRING; */
/* FORM : in STRING := ""); */
case P_TIO_OPEN:
{
open_textio('O');
break;
}
/* procedure CLOSE(FILE : in out FILE_TYPE); */
case P_SIO_CLOSE:
case P_DIO_CLOSE:
case P_TIO_CLOSE:
{
int *file_ptr;
file_ptr = get_argument_ptr(0);
filenum = *file_ptr;
check_file_open();
*file_ptr = 0;
if (operation == P_SIO_CLOSE || operation == P_DIO_CLOSE)
close_file();
else /* operation == P_TIO_CLOSE */
close_textio();
break;
}
/* procedure DELETE(FILE : in out FILE_TYPE); */
case P_SIO_DELETE:
case P_DIO_DELETE:
case P_TIO_DELETE:
{
int *file_ptr;
file_ptr = get_argument_ptr(0);
filenum = *file_ptr;
check_file_open();
strcpy(work_string, IOFNAME);
if (operation == P_SIO_DELETE || P_DIO_DELETE)
close_file();
else /* operation == P_TIO_DELETE */
close_textio();
unlink(work_string);
*file_ptr = 0;
break;
}
/* SEQUENTIAL_IO: */
/* procedure RESET(FILE : in out FILE_TYPE; MODE : in FILE_MODE); */
/* procedure RESET(FILE : in out FILE_TYPE); */
case P_SIO_RESET:
case P_SIO_RESET_MODE:
{
int newmode;
DISCARD_GENERIC_PARAMETER;
get_filenum();
check_file_open();
if (operation == P_SIO_RESET_MODE) {
newmode = get_argument_value(2);
}
else
newmode = IOMODE;
fclose(IOFDESC);
if (newmode == SIO_IN_FILE) {
IOFDESC = fopen_bin(IOFNAME, "r");
check_opened_ok();
}
else {
IOFDESC = fopen_bin(IOFNAME, "r+");
check_opened_ok();
}
IOMODE = newmode;
break;
}
/* DIRECT_IO: */
/* procedure RESET (FILE : in out FILE_TYPE; MODE : in FILE_MODE); */
/* procedure RESET (FILE : in out FILE_TYPE); */
case P_DIO_RESET:
case P_DIO_RESET_MODE:
{
int newmode;
DISCARD_GENERIC_PARAMETER;
get_filenum();
check_file_open();
if (operation == P_DIO_RESET_MODE)
newmode = get_argument_value(2);
else
newmode = IOMODE;
fclose(IOFDESC);
if (newmode == DIO_IN_FILE) {
IOFDESC = fopen_bin(IOFNAME, "r");
}
else {
IOFDESC = fopen_bin(IOFNAME, "r+");
}
check_opened_ok();
IOMODE = newmode;
DPOS = 1;
break;
}
/* TEXT_IO: */
/* procedure RESET(FILE : in out FILE_TYPE; MODE : in FILE_MODE); */
/* procedure RESET(FILE : in out FILE_TYPE); */
case P_TIO_RESET:
case P_TIO_RESET_MODE:
{
int newmode;
get_filenum();
check_file_open();
if (operation == P_TIO_RESET_MODE) {
newmode = get_argument_value(2);
/* Raise MODE_ERROR on attempt to change the mode of the
* current default input or output file. */
if ((filenum == current_in_file || filenum == current_out_file)
&& newmode != IOMODE)